#!/usr/bin/bash
# Start dir = $
# it is enough to give the directory of the configuration file
cwd=$PWD
export cwd

echo $PATH

if [ $#  -lt 1 ] ; then 
	echo "Insufficient number of input arguments"
	exit 1
fi

if [ -d  out ] ; then 
	rm -rf out
fi

#echo "" > src/data/test.tmp
# Generate new UUID. cog.py must be installed.
#python /bin/cog.py -d -o src/data/test.py $1
cp -f $1 src/data/test.py
#python CAAUuidGen.py -genIID >> src/data/test.py
cp -f src/data/test.py TestCase.py
python CheckTDDSyntax.py >> src/data/test.py
echo "Last python cmd ret code : " $?

# Replace = with colon  since that's is the Freemarker TDL syntax
sed 's/=/:/g' src/data/test.py > src/data/test.tdd

#cat TDDAppendix.py >> src/data/test.py

python src/data/test.py

if [ $? != 0 ] ; then
	exit 1
fi
#cp -f src/data/TDDTemplate.tpl src/data/test.tdd

# forloop executing a command and iterating over the results 
#for i in Uuid UuidFactory UuidIDL UuidIDLFactory UuidTypeLib
#do
#
#uuidCPP=`$uuidShell 1`
#echo $uuidCPP
#
#uuidIID=`$uuidShell 2`
#echo "Processing IID for" $i $uuidCPP $uuidIID
#
#cppValue=$i"Value"
#iidValue=$i"IIDValue"
#
##echo "sed -e "s/$r/$uuidCPP/g" -e "s/$iIIDValue/$uuidIID/g" src/data/test.tdd > src/data/test.tmp"
##sedCmd="sed -e 's/$cppValue/$uuidCPP/g' -e 's/$iidValue/$uuidIID/g' src/data/test.tmp > src/data/test.tdd"
#eval $sedCmd

#sed script uses 'single quotes' instead of "double quotes." Unix shells never expand $variables in single quotes.
#sed -e "s/UuidCPPValue/$uuidCPP/g" -e "s/UuidIIDValue/$uuidIID/g" src/data/test.tmp > src/data/test.tdd
#echo "sed -e "s/${i}Value/$uuidCPP/g" -e "s/${i}IIDValue/$uuidIID/g" src/data/test.tdd > src/data/test.tmp"
#sed -e "s/${i}Value/$uuidCPP/g" -e "s/${i}IIDValue/$uuidIID/g" src/data/test.tdd > src/data/test.tmp
#
#mv -f src/data/test.tmp src/data/test.tdd

#done
 
#exit
 
##Run fmpp via batch file as Windows environment is needed by the fmpp.exe
../Run.bat .
if [ $? != 0 ] ; then 
	exit 1
fi

#/cygdrive/c/Raman/code/CodeGen/fmpp_0.9.14/bin/fmpp -C tdd
cd out

# Run the Generated shell file to call the BitterGerne.sh file
./BitteGerneRun.sh $cwd
cd $cwd
echo Time Taken : $SECONDS

